package com.engine4cloud.tdf.education.controller.web;

import cn.hutool.core.collection.CollUtil;
import com.engine4cloud.tdf.common.core.util.R;
import com.engine4cloud.tdf.common.data.web.response.PageInfo;
import com.engine4cloud.tdf.common.data.web.response.Params;
import com.engine4cloud.tdf.common.log.annotation.SysLog;
import com.engine4cloud.tdf.education.dto.query.EduStudentQueryDTO;
import com.engine4cloud.tdf.education.dto.result.EduStudentResultDTO;
import com.engine4cloud.tdf.education.service.EduStudentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 学员
 *
 * @author wenjie
 * @date 2024-07-30 14:59:31
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/web/student")
@Tag(description = "eduStudent", name = "学员管理-web")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class EduStudentWebController {

    private final EduStudentService eduStudentService;

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @param dto  学员
     * @return R<PageInfo < EduStudentResultDTO>>
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page")
    public R<PageInfo<EduStudentResultDTO>> pageList(@ParameterObject Params page, @Valid @ParameterObject EduStudentQueryDTO dto) {
        return R.ok(eduStudentService.pageList(page, dto));
    }

    /**
     * 通过id查询学员
     *
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}")
    public R<EduStudentResultDTO> getById(@PathVariable("id") Long id) {
        return R.ok(eduStudentService.getById(id));
    }

    /**
     * 通过id删除学员
     *
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除学员", description = "通过id删除学员")
    @SysLog("通过id删除学员")
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('student_del')")
    public R<Boolean> removeById(@RequestBody Long[] ids) {
        return R.ok(eduStudentService.removeBatchByIds(CollUtil.toList(ids)));
    }
}